
export function treeDataTranslate(data, id = 'id', pid = 'parentId') {
  var res = []
  var temp = {}
  for (var i = 0; i < data.length; i++) {
    temp[data[i][id]] = data[i]
  }
  for (var k = 0; k < data.length; k++) {
    // 有 parent
    if (temp[data[k][pid]] && data[k][id] !== data[k][pid]) {
      if (!temp[data[k][pid]]['children']) { // parent没有 children
        temp[data[k][pid]]['children'] = []
      }
      if (!temp[data[k][pid]]['_level']) {
        temp[data[k][pid]]['_level'] = 1
      }
      data[k].cflag = true
      data[k]['label'] = data[k].DeviceName
      data[k]['_level'] = temp[data[k][pid]]._level + 1
      temp[data[k][pid]]['children'].push(data[k])
    } else {
      data[k]['label'] = data[k].DeviceName
      res.push(data[k])
    }
  }
  return res
}
let num = 0
export function formateD(data) {
  num++
  let flagC = true
  const temp = data[num]
  while (data.children.length >= 0) { // 有children
    temp.children ? flagC = true : flagC = false
    if (flagC) {
      temp.children = data[num].children
    } else {
      this.formateDate()
    }
  }
}
